 <template>
    <view class="topSearchBox_container">
        <image mode="widthFix" :src="bgUrl"></image>
        <slot></slot>
        <u-modal v-model="showCountDown" class="my-count-down-modal" width="600rpx" border-radius="25" :title-style="{ color: 'white' }" title="" :show-confirm-button="false">
            <view class="slot-content">
                <CircleCountDown :timestamp="timestamp" @change="countDownChange" />
                <text class="text-tip">
                    正在为您审核并领取额度中，
                    <br />
                    请您耐心等待。
                </text>
            </view>
        </u-modal>
    </view>
</template>

<script>
import { getUserId, checkHasShiMingRenZheng } from '@/utils';
import bgUrl from './topBkg/top_bkg.png';
import CircleCountDown from '@/components/circleCountDown/CircleCountDown.vue';
export default {
    name: 'swiperSearch',
    components: { CircleCountDown },
    props: {
        bgUrl: {
            type: String,
            default: bgUrl
        }
    },
    data() {
        return {
            showCountDown: false,
            isRenZheng: false,
            receiveResult: null,
            timestamp: 10
        };
    },
    methods: {
        countDownChange(time) {
            if (time === 0) {
				this.$emit('textIndexmethod');
                this.showCountDown = false;
                this.countDownOverCallback();
            }
        },
        countDownOverCallback() {
            if (this.receiveResult) {
                const res = this.receiveResult;
                if (res.data.isPass == 1) {
                    uni.showToast({
                        icon: 'none',
                        title: '领取成功，可前往额度管理查看'
                    });
                } else {
                    // uni.showToast({
                    //     icon: 'none',
                    //     title: res.data.reason
                    // });
					uni.navigateTo({
					    url: '/pagesMy/certificates/certificationFail?reason=' + res.data.reason
					});
                }
            } else {
                uni.showToast({
                    icon: 'none',
                    title: `领取额度失败,请一个礼拜之后再来领取！`
                });
            }
        },
        getBalance() {
            if (!this.$getUid()) {
                this.$goLogin();
                return;
            }
			uni.showLoading({
				title: '领取中'
			});
            checkHasShiMingRenZheng()
                .then((obj) => {
                    console.log('认证信息', obj);
                    this.isRenZheng = obj.checkResult;
                    if (this.isRenZheng) {
                        if (obj.isReceive == undefined || obj.isReceive == 0) {
                            //已认证未领取额度的情况下 可直接点击领取额度
                            this.receiveResult = null;
                            this.$request('member/mall/aliPay/balanceTradeRecord/receiveBalance', { uid: getUserId() }, 'GET')
                                .then((res) => {
                                    this.showCountDown = true;
									uni.hideLoading();
                                    this.receiveResult = res;
                                })
                                .catch((e) => {
                                    this.showCountDown = false;
                                    this.receiveResult = null;
                                    uni.showToast({
                                        icon: 'none',
                                        title: e.errorMessage
                                    });
                                    console.log('已认证未领取额度catch', e);
                                });
                        } else {
                            //已经领取过直接进入额度 管理
                            this.$onTo('/pagesOther/commission-rich/commission-rich');
                        }
                    } else {
                        //新增balanceType ==1  为领取注册额度类型
                        this.$onTo('/pagesMy/certificates/certificates?balanceType=1');
                    }
                })
                .catch((e) => {
                    console.log('认证信息catch', e);
                    this.isRenZheng = false;
                });
        }
    }
};
</script>

<style lang="scss" scoped>
.topSearchBox_container {
	
    position: relative;
    margin-bottom: 10rpx;
    uni-image {
        width: 100%;
    }
}
/deep/.my-count-down-modal {
    .u-mask {
        background-color: rgba(255, 255, 255, 0.5) !important;
        filter: blur(6px);
        backdrop-filter: blur(6px);
    }
    .u-drawer-content {
        overflow: visible !important;
        margin-top: -20%;
        .u-mode-center-box {
			background-color: transparent;
			
            height: 100rpx !important;
            // background-color: rgba(0, 0, 0, 0.95) !important;
            // border: 8rpx solid black;
            overflow: visible !important;
            // box-shadow: 18rpx 18rpx 30rpx rgba(0, 0, 0, 0.2), -18rpx -18rpx 30rpx rgba(255, 255, 255, 1);
            transition: all 0.2s ease-out;
        }
        .uni-scroll-view {
            overflow: visible !important;
        }
    }

    .u-model {
        margin-top: 10rpx;
        overflow: visible !important;
        background-color: transparent;
        .u-model__title {
            display: none;
            white-space: pre-wrap;
            font-family: 'SF Pro SC', 'SF Pro Display', 'SF Pro Icons', 'PingFang SC', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
        }
        .u-model__content {
            text-align: center;
            .slot-content {
                .my-count-down {
                    margin-top: -3%;
                    .u-countdown-item {
                        background-color: transparent !important;
                        .u-countdown-time {
                            font-size: 75rpx !important;
                            color: #fff !important;
                        }
                    }
                }
                .text-tip {
                    // width: 270%;
                    display: block;
                    color: #282828;
                    margin-top: 10%;
                    font-size: 30rpx;
                    font-family: 'SF Pro SC', 'SF Pro Display', 'SF Pro Icons', 'PingFang SC', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
                    // transform: translateX(-28%);
                }
                .u-countdown-colon {
                    color: #fff !important;
                    font-size: 40rpx !important;
                }
            }
        }
    }
}
</style>
